<template>
	<view class="main">
		<view class="head-data">
			<view class="head-data-title">
				自定义时间：
			</view>
			<view class="head-data-time" @click="show()">
				<view v-if="flag">
					<text class="header-time-view-text">{{params.startDateStr}}</text>
					<text> ~ </text>
					<text class="header-time-view-text">{{params.endDateStr}}</text>
				</view>
				<u-icon name="arrow-right" size="16"></u-icon>
			</view>

		</view>
		<u-calendar :show="startTimePickerShow" round="10" mode="range" @confirm="confirm" :allowSameDay="true" :minDate="timesTempMin"
			:maxDate="timesTempMax" monthNum="36" startText="开始" endText="结束" @close="startTimePickerShow=false">
		</u-calendar>
	</view>
</template>

<script>
	export default {
		props: {
			param: {
				startDateStr: '',
				endDateStr: '',
			}
		},
		data() {
			return {
				startTimePickerShow: false,
				params: {
					startDateStr: '',
					endDateStr: '',
				},
				flag: true,
				timesTempMin: '',
				timesTempMax: '',
				endTime: '',
				startTime: '',
			}
		},
		onLoad() {

		},
		onReady() {
			console.log("onReady")
			// this.params.startDateStr = uni.$u.timeFormat(this.params.startDateStr, 'yyyy-mm-dd');
			// this.params.endDateStr = uni.$u.timeFormat(this.params.endDateStr, 'yyyy-mm-dd');
			
			// let date = new Date;
			// date.setFullYear(date.getFullYear() - 2)
			// this.timesTempMin = date.getTime();
			// let date2 = new Date;
			// date2.setFullYear(date.getFullYear() + 2)
			// this.timesTempMax = date2.getTime();
			
			this.timesTempMin = Number(new Date().setFullYear((new Date().getFullYear() - 1)))
			this.timesTempMax = Number(this.$date.getEndDate())
		},
		methods: {

			show() {
				this.startTimePickerShow = true;
			},
			confirm(e) {
				console.log(e)
				this.params.startDateStr = e[0]
				this.params.endDateStr = e[e.length - 1]
				this.startTimePickerShow = false;
				this.$emit('params', this.params)
			},
		},
		watch: {

			param(item) {
				console.log("watch-param更新")
				this.params.startDateStr = item.startDateStr
				this.params.endDateStr = item.endDateStr
			},
			startTimePickerShow() {
				this.flag = true
			},
			endTimePickerShow() {
				this.flag = true
			}
		}
	}
</script>
<style lang="less" scoped>
	.main {
		padding: 20rpx 20rpx;
		.head-data {
			display: flex;
			justify-content: space-between;
			align-items: center;
			font-size: 26rpx;
			color: rgba(0, 0, 0, 0.6);

			.head-data-time {
				display: flex;
				justify-content: space-between;
				align-items: center;

				.header-time-view-text {
					margin: 0 15rpx;
				}
			}
		}
	}
</style>
